package cron

import (
	"zimuzu_cvn_web_api/config"
	"zimuzu_cvn_web_api/model"
	. "zimuzu_cvn_web_api/pkg/e"
)

//租赁订单到期处理
func RentOrderExpire() {
	if config.C.RunMode == "debug" {
		return
	}

	orders, err := model.GetRentOrderExpire(config.C.DB.DB)
	if err != nil {
		Log("err", err)
		return
	}
	ordersLen := len(orders)
	if ordersLen == 0 {
		Log("err", "数据为空已返回")
		return
	}
	for _, order := range orders {
		ok, err := model.ReturnTokenTrans(config.C.DB.DB, order)
		if err != nil {
			Log("err", err)
			continue
		}
		if !ok {
			Log("err", "令牌过期退回失败")
			continue
		}
	}
}
